﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Text;
using vdos.jobseeker.Model;

namespace vdos.jobseeker.Dao
{
    public class MessageDao:ITopLinkDao
    {
        public int Add(object obj)
        {
            var rs = 0;
            try
            {
                var db = new jobseekerEntities();
                var objAdd = (Model.Jobs)obj;
                db.AddToJobs(objAdd);
                rs = db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rs;
        }

        public int Update(object obj)
        {
            var rs = 0;
            try
            {
                var db = new jobseekerEntities();
                var objUpdate = (Message)obj;
                var id = objUpdate.MessageID;
                var oldObj = db.Message.FirstOrDefault(t => t.MessageID == id);
                if (oldObj != null)
                {
                    oldObj.CategoryID = objUpdate.CategoryID;
                    oldObj.MsgTitle = objUpdate.MsgTitle;
                    oldObj.MsgSubTitle = objUpdate.MsgSubTitle;
                    oldObj.MsgLead = objUpdate.MsgLead;
                    oldObj.MsgContent = objUpdate.MsgContent;
                    oldObj.MsgPostDate = objUpdate.MsgPostDate;
                    oldObj.MsgHomeImage = objUpdate.MsgHomeImage;
                    oldObj.MsgImageComment = objUpdate.MsgImageComment;
                    oldObj.MsgHistory = objUpdate.MsgHistory;
                    rs = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rs;
        }

        public int Delete(object obj)
        {
            var rs = 0;
            
            return rs;
        }
    }
}
